<!DOCTYPE html>
<html>
<script src="${request.getContextPath()}/themes/admin/js/dateutil.js" type="text/javascript"></script>
<#include "../head.html">
<link rel="stylesheet" type="text/css" href="${webroot}/plugins/fancybox/jquery.fancybox-1.3.4.css" />
    <body class="full">
    <div class="mc">
        <div class="mc-l">
            <!--左侧导航---{-->
            <div id="navPanelContainer">
                <div class="system-logo cd"></div>
                <!--管理员信息---{-->
                <#include "../adminInfo.html">
                    <!--管理员信息---}-->
                    <div class="nav-wrap">
                        <#include "left.html">
                    </div>
            </div>
            <!--左侧导航---}-->
        </div>
        <div class="mc-m">
            <div class="navToggle"></div>
        </div>
        <div class="mc-r">
            <!--顶部导航---{-->
            <#include "../topNav.html">
                <!--顶部导航---}-->

                <!--面包屑导航---{-->
                <#assign moduleName="审核借款标">

                    <#include "banner.html">
                        <!--面包屑导航---}-->

                        <!--工具栏--{-->
                        <div id="toolbar" class="clearfix">

                            <div class="toolbor-module">

                                <input type="button" class="input-button return" value="返回" onclick="javascript:location.href='showTrialBorrow.html'">
                            </div>
                        </div>
                        <!--工具栏--}-->

                        <div id="main" class="clearfix">
                            <form name="form1" method="post" action="" onsubmit="return checkApr();" enctype="multipart/form-data">



                                <div id="audit">
                                    <div class="top">
                                        <strong>设置预售时间</strong>
                                    </div>
                                    <div class="v">

                                        <div class="c">
                                            <div class="choose" style="margin-bottom: 10px;">
                                                <label class="mr15">是否预售倒计时:</label>
                                                <input  id="countdownFlag0" type="radio" name="countdownFlag" value="0" checked="checked"/>
                                                <label for="countdownFlag0"><font color="red">否</font></label>&nbsp;&nbsp;
                                                <input id="countdownFlag1"  type="radio" name="countdownFlag" value="1"/>
                                                <label for="countdownFlag1"> <font color="red">是</font></label>&nbsp;&nbsp;
                                                <input id="preSaleTime" type="text" name="preSaleTime" style="display:none" disabled="disabled" class="input_border"
                                                       value="${dateformat("nowDate")?string('yyyy-MM-dd HH:mm:ss')}" style="width:250px;" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',onpicked:pickedFunc})" readonly=""/>
                                                </assign>
                                            </div>
                                            <#if b.approvalTime ?? && timeSwitch == 1>
                                                <div class="choose" style="margin-bottom: 10px;">
                                                    <label class="mr15">项目理财时间：</label>
                                                    <label class="mr15">
                                                        <input id="lazyFlag1" name="flag" value="1" type="radio" class="radio" checked="checked"/>
                                                        按运营发布时间计算(
                                                        <#if b.isday==1>
                                                            <span id="total">${b.timeLimitDay!"-"}天</span>
                                                            <#else>
                                                                <span id="total">${b.timeLimit!"-"}个月</span>
                                                        </#if>
                                                        )
                                                    </label>
                                                    <label><input id="lazyFlag2" name="flag" type="radio" value="2" disabled class="radio" >按债权生效时间计算<span id="limitDay"></span>
                                                        <span style="color:red;">(债权生效时间：<span id="approvalTime">${b.approvalTime?string('yyyy-MM-dd')}</span>)</label>
                                                </div>
                                            </#if>

                                            <div class="choose" style="margin-bottom: 10px;">
                                                <label class="mr15" style="display:inline-block;width:90px">年利率：</label>
                                                <label class="mr15">
                                                    <input type="text" id="apr" name="apr" value="${b.apr!''}" style="width:50px">&nbsp;&nbsp;%
                                                </label>
                                                <label class="mr15"><input name="isNewHand" type="checkbox" value="1" <#if b.isNewHand==1>checked="checked"</#if>>是否新手专享（ <font color="red">若勾选则该项目为新手专享项目，只有新手（无任何投资记录的用户）才能投资，默认为不勾选，所有用户都可投资！</font>）</label>
                                            </div>
                                            <div class="choose" style="margin-bottom: 10px;">
                                                <label class="mr15" style="display:inline-block;width:90px">奖励收益：</label>
                                                <label class="mr15">
                                                    <input type="text" id="extraApr" name="extraApr"  style="width:50px" value="${b.extraAwardApr!''}"> %
                                                </label>
                                                <label class="mr15">说明  </label>
                                                <label class="mr15">
                                                    <input type="text" id="extraDesc" name="extraDesc">
                                                </label>

                                                <label class="mr15">链接地址 </label>
                                                <label class="mr15">
                                                    <input type="text" id="extraUrl" name="extraUrl" style="width:500px">
                                                </label>

                                            </div>

                                            <div class="choose" style="margin-bottom: 10px;">
                                                <label class="mr15" style="display:inline-block;width:90px">定向密码：</label>
                                                <span class="mr15">
                                            	  		<input type="text" id="pwd" name="pwd" value="<#if b.pwd??>${b.pwd}</#if>" style="width:100px">
                                            	  		<input type="radio"  name="mostLimit" value="1" >单笔最高限制
                                            	  		<input type="radio"  name="mostLimit" value="2" >单人最高限制
                                            	  		<input type="text"  id="mostAmout" name="mostAmout" value="" >
                                            	  </span>

                                            </div>
                                        </div>
                                        <div class="choose" style="margin-bottom: 10px;">
                                            <label class="mr15" style="display:inline-block;width:90px">起投金额：</label>
                                            <label class="mr15">
                                                <input type="text"   name="lowestAccount" value="<#if b.lowestAccount??>${b.lowestAccount?c}</#if>" onkeyup="value=value.replace(/[^0-9.]/g,'')">
                                            </label>

                                        </div>
                                        <div class="choose" style="margin-bottom: 10px;">
                                            <label class="mr15" style="display:inline-block;width:90px">标名后缀：</label>
                                            <label class="mr15">
                                                <input type="text"   name="suffix" value="<#if b.name.split('\\(')[1]??>(${b.name.split('\\(')[1]!''}</#if>" >
                                            </label>

                                        </div>
                                    </div>
                                    <div class="other clearfix">
                                        <input type="hidden" id="borrowAccount" value="${(b.account!0)?c}" />
                                        <input type="hidden" name="id" value="${(b.id!0)?c}" />
                                        <input type="hidden" name="actionType" value="verify" />
                                        <input type="submit"  name="reset" value="确定" class="input-button confirm"/>
                                    </div>
                                </div>
                        </div>

                        </form>

                        <script>

                            function checkApr(){
                                var lowestAccount = Number($("#lowestAccount").val());
                                var mostAmout = Number($("#mostAmout").val());
                                var borrowAccount =  Number($("#borrowAccount").val());


                                if(lowestAccount<1){
                                    alert("起投金额不能小于1！");
                                    return false;
                                }
                                if(lowestAccount>borrowAccount){
                                    alert("起投金额不能超过借款总额！");
                                    return false;
                                }
                                if(mostAmout>borrowAccount){
                                    alert("单笔或单人限额不能超过借款总额！");
                                    return false;
                                }
                                if(mostAmout>0 && lowestAccount>=mostAmout){
                                    alert("起投金额不能高于单笔或单人限额！");
                                    return false;
                                }
                                //效验预售时间
                                var preTime = new Date($('#preSaleTime').val()).getTime();
                                var nowTime = new Date().getTime();
                                if(preTime <= nowTime){
                                    alert("预售时间必须大于当前时间！");
                                    return false;
                                }

                                var oApr = $("#apr").val();
                                if(oApr ==""){
                                    alert("利率不能为空！");
                                    return false;
                                }
                                if(oApr <= 0 || oApr > 24){
                                    alert("利率区间不符合！");
                                    return false;
                                }

                            }
                            $("#countdownFlag0").click(function(){
                                $("#preSaleTime").attr("disabled","disabled").hide();
                                $("#lazyFlag2").attr("disabled",true);
                                $("#limitDay").html("");
                            });
                            $("#countdownFlag1").click(function(){
                                $("#lazyFlag2").attr("disabled",false);
                                $("#preSaleTime").removeAttr("disabled").show();
                                var approvalTime = $("#approvalTime").html();
                                if(approvalTime != null && approvalTime != undefined && approvalTime != ""){
                                    var approvalTime = $("#approvalTime").html().toString();
                                    var ss = approvalTime.split(" ");
                                    var approvalDate = new Date(Date.parse(ss[0]));
                                    approvalDate.setHours(0);
                                    approvalDate.setMinutes(0);
                                    approvalDate.setSeconds(0);

                                    var preSaleTime = $("#preSaleTime").val();
                                    var ss = preSaleTime.split(" ");
                                    var preSaleDate = new Date(Date.parse(ss[0]));
                                    preSaleDate.setHours(0);
                                    preSaleDate.setMinutes(0);
                                    preSaleDate.setSeconds(0);

                                    var totalDay = $("#total").text();
                                    if(totalDay.indexOf("天") > 0){
                                        var day = totalDay.slice(0, totalDay.indexOf("天"));
                                        approvalDate = approvalDate.addDays(new Number(day));
                                    }else{
                                        var month = totalDay.slice(0, totalDay.indexOf("个月"));
                                        approvalDate = approvalDate.addMonths(new Number(month));
                                    }
                                    var result = (approvalDate.getTime() - preSaleDate.getTime())/(3600*24*1000);
                                    $("#limitDay").html("("+ result +"天)");
                                }
                            });



                            //选择时间后计算
                            function pickedFunc(){
                                //二次审批时间节点计算
                                var approvalTime = $("#approvalTime").html();
                                if(approvalTime != null && approvalTime != undefined && approvalTime != ""){
                                    var ss = approvalTime.split(" ");
                                    var approvalDate = new Date(Date.parse(ss[0]));
                                    approvalDate.setHours(0);
                                    approvalDate.setMinutes(0);
                                    approvalDate.setSeconds(0);

                                    //预发布时间计算
                                    var y = $dp.cal.getP('y');
                                    var m = $dp.cal.getP('M');
                                    var d = $dp.cal.getP('d');
                                    var preDate = new Date(y,m-1,d,0,0,0);

                                    //按照默认显示时间
                                    var totalDay = $("#total").text();

                                    if(totalDay.indexOf("天") > 0){
                                        var day = totalDay.slice(0, totalDay.indexOf("天"));
                                        approvalDate = approvalDate.addDays(new Number(day));
                                    }else{
                                        var month = totalDay.slice(0, totalDay.indexOf("个月"));
                                        approvalDate = approvalDate.addMonths(new Number(month));
                                    }
                                    var result = (approvalDate.getTime() - preDate.getTime())/(3600*24*1000);
                                    $("#limitDay").html("("+ result +"天)");
                                }
                            }
                        </script>
        </div>
        </div>
    </div>
    <div class="mc-b"><#include "../foot.html"></div>
    <div class="msgClass">${rsmsg!""}</div>
    <#include "../jsPage.html">
    </body>
</html>

